package user_manager

import (
	"GraduationProject/public/db"
	"GraduationProject/public/models"
	"GraduationProject/webserver/controllers/util"
	"github.com/gin-gonic/gin"
)

// todo: 获取用户信息
func GetUsers(c *gin.Context) {
	if _, err := util.AdminFilter(c); err != nil {
		return
	}
	offset := c.PostForm("offset")
	limit := c.PostForm("limit")

	var count int
	db.DB.Model(&models.User{}).
		Where("`authorization` <> ?", models.UserAuthAdministrator).
		Count(&count)
	var users []models.User
	db.DB.Where("`authorization` <> ?", models.UserAuthAdministrator).
		Offset(offset).Limit(limit).Find(&users)

	c.JSON(200, gin.H{
		"status":  10000,
		"message": "success",
		"users":   users,
		"count":   count,
	})
}
